#ifndef __qytabnavigator__
#define __qytabnavigator__

#include <qframe.h>
#include <qmap.h>

class QListWidget;
class QListWidgetItem;

/*! \class QyTabNavigator
	\brief Навигатор в стиле MSVS для QyTabWidget.
*/

class QyTabNavigator : public QFrame {
	Q_OBJECT
public:
	QyTabNavigator( QWidget * parent=0 );

	QListWidgetItem * selectedItem() const;
	QListWidgetItem * selectedSectionItem() const;
	int itemIndex( QListWidgetItem * item ) const;
	int selectedItemIndex() const;
	QString selectedSection() const;
	bool isKeepWindow() const { return p_keepWindow; }

public slots:
	void addSection( const QString & name, const QStringList & items, int defaultIndex );
	void clear();
	void setCurrentSection( const QString & name );
	void setCurrentItem( const QString & section, int index );
	void setKeepWindow( bool keep ) { p_keepWindow = keep; }

signals:
	void itemChanged( const QString & section, int index );

private slots:
	void sectionActivated( QListWidgetItem * item );
	void itemActivated( QListWidgetItem * item );

private:
	void updateList();
	void keyPressEvent( QKeyEvent * event );
	void keyReleaseEvent( QKeyEvent * event );
	void emit_itemChanged( const QString & section, int index );

	struct QySection {
		QStringList items;
		int index;

		QySection( const QStringList & l=QStringList(), int i=-1 ) : items(l), index(i) {}

	};

	int p_lastTrueIndex;
	QString p_lastTrueSection;
	QListWidget * p_sectionList,
		* p_itemList;
	QMap<QString,QySection> p_sections;
	bool p_keepWindow;

};

#endif/*__qytabnavigator__*/
